<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hotel extends Front_Controller 
{
	public $m_arrTopHotelInfo = array();
	public $m_arrNewHotelInfo = array();
	public $m_arrHotHotelInfo = array();
	
	public $m_arrHotelInfo    = array();
	
	public static $m_arrTpl = array('top' => 'hotel_top',
									'new' => 'hotel_new',
									'hot' => 'hotel_hot',);
	
	public $m_arrPublic      = array();
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form'));
		$this->load->model('front/Hotel_mdl');
		$this->load->model('front/Hotel_room_mdl');
		$this->load->model('front/City_mdl');
		$this->load->model('front/Price_mdl');
		$this->load->model('front/Frontget_ml');
		$this->load->model('front/Search_m');
		$this->load->model('front/Hotel_order_mdl');		
		$this->siteSetings=$this->Frontget_ml->get_site_settings();	//��ȡվ������
		$this->announcement=$this->Frontget_ml->get_announcement();	//��ȡ��վ����		
		$this->lineclass=$this->Frontget_ml->get_lineclass();//��ȡ��·����
		$this->TicketClass=$this->Frontget_ml->getTicketClass();//��ȡ�����
		$this->newsclass=$this->Frontget_ml->get_newsclass();//��ȡ�����
		$this->des_tags=$this->Search_m->get_des_tags();	//��ȡ��ǩ����	
		$this->tagsclass=$this->Frontget_ml->get_tagsclass();//获取攻略分类

		$this->load->library('form_validation');
		$this->model=9	;		//酒店信息model为9
		$current_title     = $this->siteSetings["site_description"];
		$this->m_arrPublic =   array("newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"lineclass"=>$this->lineclass,"des_tags"=>$this->des_tags,"current_title"=>$current_title,"siteSetings"=>$this->siteSetings,"tagsclass"=>$this->tagsclass);
	}
	
	public function index()
	{
		foreach (self::$m_arrTpl as $k => $v)
		{
			$this->m_arrHotelInfo[$k] = $this->Hotel_mdl->getHotelInfoByType($v);
		}
		
		$city  = $this->City_mdl->getCityList();
		$price = $this->Price_mdl->getPriceList();
		$SliderLines = $this->Hotel_mdl->getSliderLines();
		$data  = $this->m_arrHotelInfo + $this->m_arrPublic;
		$data += $city;
		$data += $price;
		$data += $SliderLines;
		$data["model"] = $this->model;
        $this->load->view('hotel',$data);
	}
	public function flashXml_v(){
		$SliderLines=$this->Hotel_mdl->getSliderLines();//获取幻灯片
		$data=array("slider_lines"=>$SliderLines);
		$this->load->view('flashXml_v',$data);
	}	
	public function hotel_show($id = 1)
	{  
	    // 单个酒店的基本信息
	    $data = $this->Hotel_mdl->getHotelInfoById($id);
	    
	    // 酒店的房间信息
	    $arrRoom = $this->Hotel_room_mdl->getHotelRoomInfoByHotelName($id);
	    
	    
	    $data['room'] = $arrRoom;
	    $data += $this->m_arrPublic;
	    
	    $this->load->view('hotel_show',$data);
	}
	
	public function hotelSearch()
	{
		$this->_hotelSearch_post();
	}	
	public function _hotelSearch_post()
	{
		//分页
		$dllCity  = $this->input->post("dllCity");	//目的地城市ID
	//	$ddlhArea = $this->uri->segment(4);	//所在地区ID
		$dllRMB   = $this->input->post("dllRMB");	//价位
		$txthName   = $this->input->post("txthName");	//名称
	//	$ddlStar  = $this->uri->segment(6);	//酒店星级id
		
		$this->load->library('pagination');
		$config['base_url'] = site_url('/hotel/hotel_list/'.$dllCity.'/'.$dllRMB.'/'.$txthName.'/');
		$type=0	;
		$total_rows= $this->Hotel_mdl->searchHotel($dllCity,$dllRMB,$txthName,$type);//获取查询条件下的记录总数
		//print_r($total_rows);
		$config['total_rows'] =$total_rows[0]["icount"];
		$config['per_page'] = 10;
		$config['uri_segment'] = 6;
		$config['full_tag_open'] = '';
		$config['full_tag_close'] = '';
		$config['cur_tag_open']= '&nbsp;<span class="current">';
		$config['cur_tag_close']= '</span>';
		$config['prev_link']= '上一页';
		$config['next_link']= '下一页';
		$config['first_link']= ' 首页';
		$config['last_link']= ' 尾页';
		$this->pagination->initialize($config);
		$begin_record=$this->uri->segment(6);	
		$type=1;
		$searchHotel = $this->Hotel_mdl->searchHotel($dllCity,$dllRMB,$txthName,$type,$begin_record,$config['per_page']);//获取线路列表		
		// 分页END
    	
    	foreach ($searchHotel as $index => &$arr)
    	{
    		$arr['room'][$index] = $this->Hotel_room_mdl->getHotelRoomInfoByHotelName($arr['id']);
    	}
    	
    	$data['hotel'] = $searchHotel;
		$data  += $this->m_arrPublic;
		$data  += $this->City_mdl->getCityList();
		$data  += $this->Price_mdl->getPriceList();

		$this->load->view('hotel_list',$data);
	}
	
	public function hotel_order($p_hotel_name)
	{
		$room_type    = $this->uri->segment(4);	
		$room_price   = $this->uri->segment(5);
		$room_id   = $this->uri->segment(6);
		$data = array('hotel_name'=> $p_hotel_name,
					  'room_type' => $room_type,
					  'room_price'=> $room_price,
					  'room_id'=> $room_id);
		
		$data  += $this->m_arrPublic;
		$this->load->view('hotel_order',$data);
	}
	
	public function add_hotel_order()
	{
		$this->_add_hotel_order_post();
	}
	public function _add_hotel_order_post()
	{
		$arrOrder              = array(
            'room_id'        =>  $this->input->post('room_id', TRUE),
            'hotel_name'       =>  $this->input->post('hotel_name', TRUE),
            'room_nums'        =>  $this->input->post('room_nums', TRUE),
			'room_type'        =>  $this->input->post('room_type', TRUE),
            'user_name'        =>  $this->input->post('user_name', TRUE),
            'user_tel'         =>  $this->input->post('user_tel', TRUE),
            'user_card'        =>  $this->input->post('user_card', TRUE),
	        'room_price'       =>  $this->input->post('room_price', TRUE),
		    'in_time'          =>  $this->input->post('in_time', TRUE),
		    'out_time'         =>  $this->input->post('out_time', TRUE),
		    'advance_time'     =>  $this->input->post('advance_time', TRUE),
		    'late_time'        =>  $this->input->post('late_time', TRUE),
		    'remark'           =>  $this->input->post('remark', TRUE),

        );
        $id = $this->Hotel_order_mdl->add_hotel_order($arrOrder);
        
      
        redirect(site_url("/hotel/hotel_order_ok/$id"));
        
        
	}
	
	public function hotel_order_ok($p_id)
	{
		$arrRet = $this->Hotel_order_mdl->get_hotel_order($p_id);
		$data   = $arrRet[0];
		
//		print_r($data);
//		exit;
		$data += $this->m_arrPublic;
		$data['money'] = $data['room_nums']* $data['room_price'];
		
		$this->load->view('hotel_order_ok',$data);
	}
}
